<?php
define('ROOT_DIR'	, realpath('../' . dirname(basename(__FILE__))));
define('ADMIN_USERNAME','henantrua'); 	// Admin Username
define('ADMIN_PASSWORD','error');  	// Admin Password
////////// END OF DEFAULT CONFIG AREA /////////////////////////////////////////////////////////////
///////////////// Password protect ////////////////////////////////////////////////////////////////
/*if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
	$_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME ||$_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD) {
	Header("WWW-Authenticate: Basic realm=\"Memcache Login\"");
	Header("HTTP/1.0 401 Unauthorized");
	echo '
		<html><body>
		<h1>Rejected!</h1>
		<big>Wrong Username or Password!</big>
		</body></html>
	';
	exit;
}*/
echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><body>';
//require_once 'base.php';
if(!isset($_GET['file'])) {
	$d = isset($_GET['d']) ? $_GET['d'] : date('Y/m/d');
	$f = ROOT_DIR . '/data/log/' . $d . '/db.txt';
} else {
	$f = ROOT_DIR . '/data/log/' . $_GET['file'] . '.txt';
}
if (is_file($f)) {
	$intPage  	= isset($_GET['page']) ? $_GET['page'] : 1;
	$intLimit 	= 100;
	$intOffset	= ($intPage - 1) * $intLimit;
	$data 		= file_get_contents($f);
	$arrLog 	= explode("::::", $data);
	$arrLog		= array_slice($arrLog, $intOffset, $intLimit);
	$arrLog 	= array_reverse($arrLog);
	$html = '<table width="100%">';
	for ($i = 0; $i < count($arrLog); $i++)	{
		if (trim($arrLog[$i]) != '') {
			$strStyle = ($i%2 == 1 ? 'style="background-color:#DDDDDD"' : 'style="background-color:#EEEEEE"');
			$html .= '<tr><td width="30px" valign="top" ' . $strStyle . '>' . $i . '</td><td ' . $strStyle . '>' . $arrLog[$i] . '</td></tr>';
		}
	}
	$html .= "</table>";
	echo $html;
	if (count($arrLog) >= 1000) {
		unlink($f);
	}
}
echo '</body></html>';
?>